<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/9
 * Time: 12:41
 */

namespace common\business\ifs;


use common\business\CommonHelper;
use common\business\Handler;
use common\consts\CommonResources;
use common\models\Log;
use common\result\ActionResult;
use yii\helpers\Json;
use Yii;

class DbLog extends Handler implements LogInterface
{
    /**
     * @param $log Log
     * @return bool
     */
    public function persistLog($log)
    {
        $actionIsSuccess = $log->save();
        if (!$actionIsSuccess) {
            $dbErrorMsg = Json::encode($log->getErrors());
            $this->addError('SaveRecordWithLog', $dbErrorMsg);
            $log->memo = $log->memo . ' | ' . CommonResources::ACTION_FAIL_MSG('Save', 'Record', $dbErrorMsg);
            Yii::error(CommonResources::ACTION_FAIL_MSG('Save', 'Log', $log->memo));
        }
        return $actionIsSuccess;
    }
}